<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="项目编号" prop="projectCode">
        <el-input
          v-model="queryParams.projectCode"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="招标类型" prop="projectTypeId">
        <el-select v-model="queryParams.projectTypeId" clearable placeholder="请选择">
          <el-option
            v-for="item in projecttypeList"
            :key="item.id"
            :label="item.text"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="招标方式" prop="projectTenderModeId">
        <el-select v-model="queryParams.projectTenderModeId" clearable placeholder="请选择">
          <el-option
            v-for="item in projecttendermodeList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="所属部门" prop="projectDeptId">
        <treeselect v-model="queryParams.projectDeptId" :options="deptList" :show-count="true" placeholder="请选择归属部门" style="width: 200px"/>
      </el-form-item>

      <el-form-item label="资质主体" prop="projectAgencyId">
        <el-select v-model="queryParams.projectAgencyId"  clearable placeholder="请选择" >
          <el-option
            v-for="item in projectagencyList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>


      <el-form-item label="资金来源" prop="projectFundingSourceId">
        <el-select v-model="queryParams.projectFundingSourceId"  clearable placeholder="请选择" >
          <el-option
            v-for="item in projectfundingsourceList"
            :key="item.id"
            :label="item.text"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>


      <el-form-item label="委托业主" prop="projectTenderee">
        <el-input
          v-model="queryParams.projectTenderee"
          placeholder="请输入委托业主"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评标时间" prop="projectBidMakeTime">
        <el-date-picker clearable
          v-model="queryParams.projectBidMakeTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择评标时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="expertselectList">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="项目编号" align="center" prop="projectCode" />
      <el-table-column label="招标类型" align="center" prop="projectTypeName" />
      <el-table-column label="招标方式" align="center" prop="projectTenderModeName" />
      <el-table-column label="所属部门" align="center" prop="projectDeptName" />
      <el-table-column label="评标方法" align="center" prop="projectBidevaluationModeName" />
      <el-table-column label="资金来源" align="center" prop="projectFundingSourceName" />
      <el-table-column label="委托业主" align="center" prop="projectTenderee" />
      <el-table-column label="评标时间" align="center" prop="projectBidMakeTime" />
      <el-table-column label="资质主体" align="center" prop="projectAgencyName" />
      <el-table-column label="抽取专家数" align="center" prop="projectSectionQty" />
      <el-table-column label="业主代表数" align="center" prop="projectBidderQty" />
      <el-table-column label="设置数量" align="center" prop="expertPriorNum" />
      <el-table-column label="状态" prop="status"  width="100">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 1">抽取已保存</el-tag>
          <el-tag v-if="scope.row.status === 2" type="success">抽取已确认</el-tag>
          <el-tag v-if="scope.row.status === 0" type="info">待抽取</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="left" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.extractedNum > 0"
            @click="showExpertExtract(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            @click="setProjectExpertPrior(scope.row)"
          >设置</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改专家抽取对话框 -->
    <el-dialog :title="projectexpertpriorTitle" :visible.sync="projectexpertpriorOpen" width="80%" append-to-body>
      <el-form :model="queryProjectexpertpriorParams" ref="queryProjectexpertpriorForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="专家姓名" prop="expertName">
          <el-input
            v-model="queryProjectexpertpriorParams.expertName"
            placeholder="请输入专家姓名"
            clearable
            @keyup.enter.native="handleExpertQuery"
          />
        </el-form-item>
        <el-form-item label="证件号码" prop="identityCode">
          <el-input
            v-model="queryProjectexpertpriorParams.identityCode"
            placeholder="请输入证件号码"
            clearable
            @keyup.enter.native="handleExpertQuery"
          />
        </el-form-item>
        <el-form-item label="手机号码" prop="mobile">
          <el-input
            v-model="queryProjectexpertpriorParams.mobile"
            placeholder="请输入手机号码"
            clearable
            @keyup.enter.native="handleExpertQuery"
          />
        </el-form-item>
        <el-form-item label="专家品目" prop="expertCategoryName">
          <el-input
            v-model="queryProjectexpertpriorParams.expertCategoryName"
            placeholder="请输入专家品目"
            clearable
            @keyup.enter.native="handleExpertQuery"
          />
        </el-form-item>
        </el-form-item>

        <el-form-item label="地区" prop="areaId">
          <el-select v-model="queryProjectexpertpriorParams.areaId" clearable placeholder="请选择">
              <el-option
                v-for="item in companyareaList"
                :key="item.areaId"
                :label="item.areaName"
                :value="item.areaId">
              </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="专家类型" prop="expertTypeId">
          <el-select v-model="queryProjectexpertpriorParams.expertTypeId" clearable placeholder="请选择">
              <el-option
                v-for="item in experttypeList"
                :key="item.id"
                :label="item.text"
                :value="item.id">
              </el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleProjectExpertPriorQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetProjectExpertPriorQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleProjectexpertpriorAdd"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="projectexpertpriorMultiple"
            @click="handleProjectexpertpriorDelete"
          >删除</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getProjectExpertPriorList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="projectexpertpriorList" @selection-change="handleProjectexpertpriorChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="专家ID" align="left" width="80"  prop="expert.id" />
        <el-table-column label="专家姓名" align="left"  width="80" prop="expertName" />
        <el-table-column label="证件号码" align="left" prop="expert.identityCode" />
        <el-table-column label="手机号码" align="left" prop="expert.mobile" />
        <el-table-column label="专家品目" align="left" prop="expert.expertCategoryName" />
        <el-table-column label="地区" align="left" prop="expert.areaName" />
        <el-table-column label="专家类型" align="left" prop="expert.expertTypeName" />
        <el-table-column label="抽取轮次" align="left" prop="number" />
      </el-table>

      <pagination
        v-show="projectexpertpriorTotal>0"
        :total="projectexpertpriorTotal"
        :page.sync="queryProjectexpertpriorParams.pageNum"
        :limit.sync="queryProjectexpertpriorParams.pageSize"
        @pagination="getProjectExpertPriorList"
      />
    </el-dialog>


    <!-- 专家列表 -->
    <el-dialog :title="expertTitle" :visible.sync="expertOpen" width="80%" append-to-body>
      <el-form :model="queryExpertParams" ref="queryExpertForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="专家姓名" prop="expertName">
          <el-input
            v-model="queryExpertParams.expertName"
            placeholder="请输入专家姓名"
            clearable
            @keyup.enter.native="handleExpertQuery"
          />
        </el-form-item>
        <el-form-item label="证件号码" prop="identityTypeId">
          <el-input
            v-model="queryExpertParams.identityCode"
            placeholder="请输入证件号码"
            clearable
            @keyup.enter.native="handleExpertQuery"
          />
        </el-form-item>
        </el-form-item>

        <el-form-item label="地区" prop="areaId">
          <el-select v-model="queryExpertParams.areaId" clearable placeholder="请选择">
              <el-option
                v-for="item in companyareaList"
                :key="item.areaId"
                :label="item.areaName"
                :value="item.areaId">
              </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="专家类型" prop="expertTypeId">
          <el-select v-model="queryExpertParams.expertTypeId" clearable placeholder="请选择">
              <el-option
                v-for="item in experttypeList"
                :key="item.id"
                :label="item.text"
                :value="item.id">
              </el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleExpertQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetExpertQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="expertList">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="ID" align="center" prop="id" />
        <el-table-column label="专家姓名" align="center" prop="expertName" />
        <el-table-column label="手机号码" align="center" prop="mobile" />
        <el-table-column label="证件类型" align="center" prop="identityTypeName" />
        <el-table-column label="证件号码" align="center" prop="identityCode" />
        <el-table-column label="地区" align="center" prop="areaName" />
        <el-table-column label="专家类型" align="center" prop="expertTypeName" />
        <el-table-column label="性别" align="center" prop="sex" />
        <el-table-column label="邮箱" align="center" prop="email" />
        <el-table-column label="专家品目" align="center" prop="expertCategoryName" />
        <el-table-column label="是否在职" align="center" prop="isOnJob" />
        <el-table-column label="最高学历" align="center" prop="highestEducation" />
        <el-table-column label="职务" align="center" prop="postition" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="addExpertPrior(scope.row)"
            >添加</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="expertTotal>0"
        :total="expertTotal"
        :page.sync="queryExpertParams.pageNum"
        :limit.sync="queryExpertParams.pageSize"
        @pagination="getExpertList"
      />
    </el-dialog>

    <!-- 添加专家弹窗 -->
    <el-dialog :title="addtitle" :visible.sync="openAdd" width="500px" append-to-body>
      <el-form ref="addForm" :model="addForm" :rules="rules" label-width="100px">
          <el-form-item label="专家名称：">
            <el-tag type="info">{{addForm.expertName}}</el-tag>
          </el-form-item>

          <el-form-item label="抽取轮次：" prop="number">
            <el-input v-model="addForm.number" placeholder="请输入专家抽取轮次" />
          </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAddForm">确 定</el-button>
        <el-button @click="cancelAdd">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看 -->
    <el-dialog :title="extractResultTitle" :visible.sync="extractResultOpen" width="60%" append-to-body>

      <el-form class="print-content" ref="print" label-width="120px" size="mini" style="1px solid #dfe6ec;" v-if="expertSelect != null">
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目编号：">{{expertSelect.projectCode}}</el-form-item>
          </el-col>
          <el-col :span="12">
             <el-form-item label="*项目名称：">{{expertSelect.projectName}}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="*招标类型：">{{expertSelect.projectTypeName}}</el-form-item>
          </el-col>
          <el-col :span="12">
             <el-form-item label="*招标方式：">{{expertSelect.projectTenderModeName}}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="*评标方法：">{{expertSelect.projectBidevaluationModeName}}</el-form-item>
          </el-col>
          <el-col :span="12">
             <el-form-item label="*资金来源：">{{expertSelect.projectFundingSourceName}}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="*委托业主：">{{expertSelect.projectTenderee}}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="*项目所属部门：">{{expertSelect.projectDeptName}}</el-form-item>
          </el-col>
          <el-col :span="12">
             <el-form-item label="资质主体：">{{expertSelect.projectAgencyName}}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="*评标时间：">{{expertSelect.projectBidMakeTime}}</el-form-item>
          </el-col>
          <el-col :span="12">
             <el-form-item label="*评标地址：">{{expertSelect.projectBidMakeAddr}}</el-form-item>
          </el-col>
        </el-row>

        <el-row v-for="(p,index) of extractResult">
          <p v-if="p">第 {{index}} 轮抽取</p>
          <el-table
              v-if="p"
              :data="p"
              border
              style="width: 100%">
              <el-table-column
                align="left"
                prop="expert.expertName"
                label="专家姓名"
                width="80">
              </el-table-column>
              <el-table-column
                align="left"
                width="200"
                prop="expert.identityCode"
                label="证件号码"
                >
              </el-table-column>
              <el-table-column
                align="left"
                prop="expert.mobile"
                label="手机号码"
                width="120">
              </el-table-column>
              <el-table-column
                align="left"
                prop="expert.technicaTitle"
                label="职称"
                >
              </el-table-column>
              <el-table-column
                align="left"
                label="专家状态"
                width="80">
                <template slot-scope="scope">
                  <el-tag v-if="scope.row.status === '0'" type="info">缺席</el-tag>
                  <el-tag v-if="scope.row.status === '1'" type="success">出席</el-tag>
                </template>
              </el-table-column>
            </el-table>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="extractResultOpen = false">关 闭</el-button>
        <el-button @click="onPrint">打 印</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listExpertselect, getExpertselect, delExpertselect, addExpertselect, updateExpertselect } from "@/api/system/expertselect";
import { listProjectexpertprior, getProjectexpertprior, delProjectexpertprior, addProjectexpertprior, updateProjectexpertprior } from "@/api/system/projectexpertprior";
import { listProjectexpertextract, listsProjectexpertextract, getProjectexpertextract, delProjectexpertextract, addProjectexpertextract, updateProjectexpertextract,setProjectexpertextractstatus,resetProjectexpertextract,confirmExpertselectextract} from "@/api/system/projectexpertextract";
import { listExpert, getExpert, delExpert, addExpert, updateExpert } from "@/api/system/expert";
import { listsProjecttendermode } from "@/api/system/projecttendermode";
import { listsProjecttype } from "@/api/system/projecttype";
import { listsCompanyarea } from "@/api/system/companyarea";
import { listsCompany } from "@/api/system/company";
import { listsType } from "@/api/system/experttype";
import { deptTreeSelect } from "@/api/system/user";
import { listsProjectfundingsource } from "@/api/system/projectfundingsource";
import print from '@/utils/print.js';

import Treeselect from "@riophae/vue-treeselect";
import Tenderer from "@/components/Tenderer";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Expertselect",
  components: {Treeselect,Tenderer },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专家抽取表格数据
      expertselectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        projectName: null,
        projectCode: null,
        projectExternaltCode: null,
        projectTypeId: null,
        projectTypeName: null,
        projectTenderModeId: null,
        projectTenderModeName: null,
        projectDeptId: null,
        projectDeptName: null,
        projectAgencyId: null,
        projectAgencyName: null,
        status: null,
        projectBidevaluationModeId: null,
        projectBidevaluationModeName: null,
        projectFundingSourceId: null,
        projectFundingSourceName: null,
        projectTendereeId: null,
        projectTenderee: null,
        projectBidMakeTime: null,
        projectBidMakeAddr: null,
        projectSectionQty: null,
        projectBidderQty: null,
        projectExpertCateIds: null,
        noCompanyIds: null,
        noCompanyName: null,
        projectExpertCategoryId: null,
        projectExpertCategoryName: null,
        noExpertId: null,
        noExpertName: null,
        expertCustomGroupId: null,
        expertCustomGroupName: null,
        sort: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },

      // ----------------------------  优先专家  ----------------------
      projectExpertPriorIds: [],
      // 非多个禁用
      projectexpertpriorMultiple: true,
      expertSelectId: "",
      // 弹出层标题
      projectexpertpriorTitle: "",
      // 是否显示弹出层
      projectexpertpriorOpen: false,
      // 查询参数
      queryProjectexpertpriorParams: {
        pageNum: 1,
        pageSize: 10,
        expertSelectId: null,
        expertId: null,
        expertName: null,
        number: null,
        identityTypeId: null,
        areaId: null,
        expertTypeId: null,
      },
      // 总条数
      projectexpertpriorTotal: 0,
      // 优先专家表格数据
      projectexpertpriorList: [],
      identitytypeList: [],
      companyareaList: [],
      experttypeList: [],

      // ----------------------------  专家列表  ----------------------
      expertTitle: "",
      expertOpen: false,
      expertTotal: 0,
      expertList: [],
      queryExpertParams: {
        pageNum: 1,
        pageSize: 10,
        expertName: null,
        mobile: null,
        identityTypeId: null,
        identityTypeName: null,
        identityCode: null,
        areaId: null,
        areaName: null,
        expertTypeId: null,
        expertTypeName: null,
        sex: null,
        email: null,
        expertCategoryId: null,
        expertCategoryName: null,
        isOnJob: null,
        workCompany: null,
        graduatedFrom: null,
        highestEducation: null,
        technicaTitle: null,
        postition: null,
        addr: null,
        isJoinExpertDb: null,
        status: null,
        bankName: null,
        bankAccount: null,
        attachmentOtherImage: null,
        attachmentImage: null,
        professionalTypeSelect: null,
        categoryCodeRemark: null,
        workingYears: null,
        userName: null,
        password: null,
        pwdPlaintext: null,
        approvalStatus: null,
        approvalRemark: null,
        fromType: null,
      },


      // -- 专家抽取弹窗 --
      expertSelect: null,
      doExpertExtractDisabled: true,
      reDoExpertExtractDisabled: true,
      resetExpertExtractDisabled: true,
      expertSelectId: null,
      expertExtractTitle: '',
      expertExtractOpen: false,
      expertExtractList: [],
      expertExtractTotal: 0,
      // 查询参数
      queryExpertExtractParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        projectName: null,
        expertSelectId: null,
        expertId: null,
        expertName: null,
        number: null,
        status: null,
      },

      // ----------------------------  添加弹窗  ----------------------
      addtitle: "",
      openAdd: false,
      // 表单参数
      addForm: {},
      // -------------------  查看抽取结果  -------------------
      extractResultTitle: '',
      extractResultOpen: false,
      extractResult:[],

      // ---------------------------- 搜索工具栏   ----------------------
      // 招标类型
      projecttypeList: [],
      // 招标方式
      projecttendermodeList: [],
      // 部门列表
      deptList: [],
      // 资质主体
      projectagencyList: [],
      // 资金来源
      projectfundingsourceList: [],

    };
  },
  created() {
    this.getList();
    this.getProjectExpertPriorList();
    this.getExpertList();
    this.getCompanyAreaList();
    this.getExpertTypeList();

    this.getProjecttypeList();
    this.getProjecttendermodeList();
    this.getDeptTree();
    this.getListsCompany();
    this.getProjectfundingsourceList();
  },
  methods: {
    /** 查询专家抽取列表 */
    getList() {
      this.loading = true;
      listExpertselect(this.queryParams).then(response => {
        this.expertselectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectId: null,
        projectName: null,
        projectCode: null,
        projectExternaltCode: null,
        projectTypeId: null,
        projectTypeName: null,
        projectTenderModeId: null,
        projectTenderModeName: null,
        projectDeptId: null,
        projectDeptName: null,
        projectAgencyId: null,
        projectAgencyName: null,
        status: null,
        projectBidevaluationModeId: null,
        projectBidevaluationModeName: null,
        projectFundingSourceId: null,
        projectFundingSourceName: null,
        projectTendereeId: null,
        projectTenderee: null,
        projectBidMakeTime: null,
        projectBidMakeAddr: null,
        projectSectionQty: null,
        projectBidderQty: null,
        projectExpertCateIds: null,
        noCompanyIds: null,
        noCompanyName: null,
        projectExpertCategoryId: null,
        projectExpertCategoryName: null,
        noExpertId: null,
        noExpertName: null,
        expertCustomGroupId: null,
        expertCustomGroupName: null,
        sort: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    resetProjectExpertPriorQuery() {
      this.resetForm("queryProjectexpertpriorForm");
      this.queryProjectexpertpriorParams.expertSelectId = this.expertSelectId;
      this.handleProjectExpertPriorQuery();
    },
    /** 搜索按钮操作 */
    handleProjectExpertPriorQuery() {
      this.queryProjectexpertpriorParams.pageNum = 1;
      this.queryProjectexpertpriorParams.expertSelectId = this.expertSelectId;
      this.getProjectExpertPriorList();
    },
    setProjectExpertPrior(row){
      this.expertSelectId = row.id;
      this.queryProjectexpertpriorParams.expertSelectId = row.id;
      this.projectexpertpriorTitle= "设置专家优先"+row.projectName;
      // 是否显示弹出层
      this.projectexpertpriorOpen= true;
      // 查询优先抓专家列表
      this.getProjectExpertPriorList();
    },
    /** 查询优先专家列表 */
    getProjectExpertPriorList() {
      this.loading = true;
      listProjectexpertprior(this.queryProjectexpertpriorParams).then(response => {
        this.projectexpertpriorList = response.rows;
        this.projectexpertpriorTotal = response.total;
        this.loading = false;
      });
    },
    // 优先专家多选
    handleProjectexpertpriorChange(selection){
      this.projectExpertPriorIds = selection.map(item => item.id)
      this.projectexpertpriorMultiple = !selection.length
    },
    handleProjectexpertpriorAdd(){
      this.getExpertList();
      this.expertTitle ="新增";
      this.expertOpen = true;
    },
    // 删除优选专家
    handleProjectexpertpriorDelete(){
      const ids = this.projectExpertPriorIds;
      const expertSelectId = this.expertSelectId;
      this.$modal.confirm('是否确认删除优先专家Id为"' + ids + '"的数据项？').then(function() {
        return delProjectexpertprior(ids,expertSelectId);
      }).then(() => {
        this.getProjectExpertPriorList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /**获取地区列表**/
    getCompanyAreaList(){
      this.loading = true;
      listsCompanyarea(this.queryParams).then(response => {
        this.companyareaList = response.data;
        this.loading = false;
      });
    },
    /**获取专家型列表**/
    getExpertTypeList(){
      this.loading = true;
      listsType(this.queryParams).then(response => {
        this.experttypeList = response.data;
        this.loading = false;
      });
    },



    /** 专家列表 */
    /** 查询专家管理列表 */
    getExpertList() {
      this.loading = true;
      listExpert(this.queryExpertParams).then(response => {
        this.expertList = response.rows;
        this.expertTotal = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleExpertQuery() {
      this.queryExpertParams.pageNum = 1;
      this.getExpertList();
    },
    /** 重置按钮操作 */
    resetExpertQuery() {
      this.resetForm("queryExpertForm");
      this.handleExpertQuery();
    },
    addExpertPrior(row){
       this.addForm.expertId = row.id;
       this.addForm.expertName = row.expertName;
       this.openAdd = true;
    },
    submitAddForm(){
      this.addForm.expertSelectId = this.expertSelectId;
      if(this.addForm.number == null){
        this.$message({
          message: '抽取轮次不能为空',
          type: 'warning'
        });
        return;
      }
      // 保存到接口
      addProjectexpertprior(this.addForm).then(response => {
        this.$modal.msgSuccess("新增成功");
        this.openAdd = false;
        this.expertOpen = false;
        this.getProjectExpertPriorList();
      });
    },
    cancelAdd(){
      this.openAdd = false;
      this.addForm = {};
    },

    //-------------------  查看专家抽取  -----------------
    showExpertExtract(row){
      console.log(row)
      // 查询抽取结果
      this.extractResult = [];
      this.expertSelect = row;
      console.log(this.expertSelect)
      this.queryExpertExtractParams.expertSelectId = row.id;
      listsProjectexpertextract(this.queryExpertExtractParams).then(response => {
        if(response.data.length > 0){
          for (var extractData of response.data) {
            if(!this.extractResult[extractData['number']]){
              this.extractResult[extractData['number']] = [];
              //this.extractResult[extractData['number']] = [extractData];
              this.extractResult[extractData['number']].push(extractData);
            }else{
              this.extractResult[extractData['number']].push(extractData);
            }
          }
          this.extractResultTitle = '查看';
          this.extractResultOpen = true;
        }
      });
      console.log(this.extractResult)
    },
    // 打印
    onPrint() {
      print(this.$refs.print);
    },

    // 工具栏
    getProjecttypeList() {
      this.loading = true;
      listsProjecttype(this.queryParams).then(response => {
        this.projecttypeList = response.data;
        this.loading = false;
      });
    },
    getProjecttendermodeList() {
      this.loading = true;
      listsProjecttendermode(this.queryParams).then(response => {
        this.projecttendermodeList = response.data;
        this.loading = false;
      });
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptList = response.data;
      });
    },
    getListsCompany() {
      this.loading = true;
      listsCompany(this.queryParams).then(response => {
        this.projectagencyList = response.data;
        this.loading = false;
      });
    },
    getProjectfundingsourceList() {
      this.loading = true;
      listsProjectfundingsource(this.queryParams).then(response => {
        this.projectfundingsourceList = response.data;
        this.loading = false;
      });
    },


  }
};
</script>
